/****************************************************************************
**
** Copyright (C) 2012 Róbert Márki
**
** This file is part of Web Feeds.
**
** Web Feeds is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Web Feeds is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Web Feeds.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

import QtQuick 1.1
import com.nokia.meego 1.0
import com.nokia.extras 1.1
import WebFeeds 1.0
import "../../../../shared/qml/UIConstants.js" as UIConstants
import "../../../../shared/qml/" as Shared
import "../misc" as Misc
import "../buttons" as Buttons

GoogleReaderPage {
    id: root

    property bool __contentsEnabled: false
    onStatusChanged: {
        if(root.status == PageStatus.Active)
            root.__contentsEnabled = true;
    }

    contents: Shared.CommonStoryPageContents {
        id: storyPageContents

        busy: root.contentsBusy
        rootItem: root.rootItem.parent
        initialRow: webFeedsApp.pageItemModel.row(root.rootItem)
        onCurrentRowChanged: {
            if(root.__contentsEnabled)
                root.changeRootItem(storyPageContents.itemForRow(row));
        }
        contentsEnabled: root.__contentsEnabled

        header: Shared.CommonDelegateHelper {
            id: headerHelper

            anchors.left: parent.left
            anchors.right: parent.right
            anchors.top: parent.top
            height: header.height

            Shared.CommonPageHeader {
                id: header
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                backgrounColor: "transparent"
                titleColor: UIConstants.HEADER_TITLE_COLOR
                subTitleColor: UIConstants.HEADER_SUBTITLE_COLOR
                multiline: true
                titleFont: UIConstants.FONT_FAMILY_LIGHT
                subTitleFont: UIConstants.FONT_FAMILY_LIGHT
                titleText: headerHelper.model.title
                subTitleText: root.service.feedTitle(headerHelper.model.feedId) + "\n" + headerHelper.model.formattedDateTime

                Shared.Separator {
                    id: separator

                    anchors.bottom: parent.bottom
                    anchors.right: parent.right
                    anchors.rightMargin: UIConstants.DEFAULT_MARGIN
                    anchors.left: parent.left
                    anchors.leftMargin: UIConstants.DEFAULT_MARGIN
                }
            }
        }
    }

    tools: Shared.CommonToolBarLayout {
        enabled: root.userInteractionEnabled
        Shared.BackToolButton {pageItem: root.rootItem; page: root}
        Buttons.StarStoryToolButton {pageItem: root.rootItem}
        Buttons.ShareStoryToolButton {pageItem: root.rootItem}
        Shared.MenuToolButton {pageItem: root.rootItem; page: root}
    }
}
